xen/arm: Introduce alternative runtime patching
authorJulien Grall <julien.grall@arm.com>
Wed, 27 Jul 2016 16:37:05 +0000 (17:37 +0100)
committerKonrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Wed, 3 Aug 2016 19:46:43 +0000 (15:46 -0400)
commit8c044700cd5205696d88d365c41c77583498f58c
tree3b9f9453206c0c47a4fc96dbe92aabac97fa1d24
parentab8fc3937eeb9332b83d7e14d81e37f0b0ef1841
xen/arm: Introduce alternative runtime patching

Some of the processor erratum will require to modify code sequence.
As those modifications may impact the performance, they should only
be enabled on affected cores. Furthermore, Xen may also want to take
advantage of new hardware features coming up with v8.1 and v8.2.

This patch adds an infrastructure to patch Xen during boot time
depending on the "features" available on the platform.

This code is based on the file arch/arm64/kernel/alternative.c in
Linux 4.6-rc3. Any references to arm64 have been dropped to make the
code as generic as possible.

When Xen is creating the page tables, all the executable sections
(.text and .init.text) will be marked read-only and then enforced by
setting SCTLR.WNX.

Whilst it might be possible to mark those entries read-only after
Xen has been patched, we would need extra care to avoid possible
TLBs conflicts (see D4-1732 in ARM DDI 0487A.i) as all
physical CPUs will be running.

All the physical CPUs have to be brought up before patching Xen because
each cores may have different errata/features which require code
patching. The only way to find them is to probe system registers on
each CPU.

To avoid extra complexity, it is possible to create a temporary
writeable mapping with vmap. This mapping will be used to write the
new instructions.

Lastly, runtime patching is currently not necessary for ARM32. So the
code is only enabled for ARM64.

Note that the header asm-arm/alternative.h is a verbatim copy for the
Linux one (arch/arm64/include/asm/alternative.h). It may contain
innacurate comments, but I did not touch them for now.

Reviewed-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Signed-off-by: Julien Grall <julien.grall@arm.com>
xen/arch/arm/Kconfig
xen/arch/arm/Makefile
xen/arch/arm/alternative.c [new file with mode: 0644]
xen/arch/arm/setup.c
xen/arch/arm/xen.lds.S
xen/include/asm-arm/alternative.h [new file with mode: 0644]
xen/include/asm-arm/arm64/insn.h